package com.hxkcloud.nurse.db;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * Created by ray_lei on 2016/7/5.
 */
public class YjhDBHelper extends SQLiteOpenHelper {



    private static final String TAG = "YjhDBHelper";
    private static final String DB_NAME = "YJH_DB";
    private static final int DB_VERSION = 1;
    private Context mContext;

    /**
     * 构造方法
     * @param context
     * @param name
     * @param factory
     * @param version
     */
    public YjhDBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory,
                          int version) {
        super(context, name, factory, version);
        this.mContext = context;
    }

    /**
     * 构造方法
     * @param context
     * @param name
     * @param version
     */
    public YjhDBHelper(Context context, String name,int version) {
        super(context, name,null, version);
        this.mContext = context;
    }

    /**
     * 构造方法
     * @param context
     * @param version
     */
    public YjhDBHelper(Context context, int version) {
        super(context, DB_NAME, null, version);
        this.mContext = context;
    }

    /**
     * 构造方法
     * @param context
     */
    public YjhDBHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
        this.mContext = context;
    }

    /**
     * 创建表
     */
    @Override
    public void onCreate(SQLiteDatabase db) {

        try {
            db.execSQL(YjhTable.YJH_USERLOGIN_CREATE);//用户登录信息表
            db.execSQL(YjhTable.YJH_BASIC_DISTRICT);//基础数据-地区数据表


        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    /**
     * 数据库更新
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.d(TAG, "oldVersion="+ oldVersion +"  |  newVersion="+newVersion);
        db.execSQL(YjhTable.YJH_USERLOGIN_EXISTS);//用户登录信息表
        db.execSQL(YjhTable.YJH_BASIC_DISTRICT_EXISTS);//基础数据-地区数据表


        db.execSQL(YjhTable.YJH_USERLOGIN_CREATE);//用户登录信息表
        db.execSQL(YjhTable.YJH_BASIC_DISTRICT);//基础数据-地区数据表
    }


}
